<%--
  Created by IntelliJ IDEA.
  User: gaosubo
  Date: 2020/10/23
  Time: 16:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用餐汇总</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/lib/layui/layui/css/eleTree.css?2019101815.40">
    <link rel="stylesheet" href="/lib/layui/layui/css/treeTable.css?2019101815.17">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/modules/layer/default/layer.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
    <%--js--%>
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
    <script type="text/javascript" src="/js/base/base.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <style>
        .layui-form-item {
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <div class="headImg" style="padding-top: 10px">
					<span style="font-size:22px;margin-left:10px;color:#494d59;margin-top: 2px"><img style="margin-left:1.5%" src="../img/commonTheme/theme6/icon_summary.png" alt="">
                        <span style="margin-left: 10px">用餐汇总</span>
                    </span>
        </div>
    </div>
    <hr class="layui-bg-cyan">
    <div class="layui-form" style="margin: 0 auto; width: 80%">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="stadate" id="stadate" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="enddate" id="enddate" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">用餐类型</label>
                <div class="layui-input-inline">
                    <select name="mealType" id="mealType" lay-verify="mealType" lay-search="">
                        <option value="">请选择</option>
                        <option value="1">访客</option>
                        <option value="2">教职工</option>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">申请人</label>
                <div class="layui-input-inline">
                    <input type="text" name="userId" id="userId" autocomplete="off" class="layui-input layui-disabled" disabled>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <a href="javascript:chooseUserId();" >选择</a>
                    <a href="javascript:EmptyUserId();" >清空</a>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">部门</label>
                <div class="layui-input-inline">
                    <input type="text" name="deptId" id="deptId" autocomplete="off" class="layui-input layui-disabled" disabled>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <a href="javascript:chooseDeptId();" >选择</a>
                    <a href="javascript:EmptyDeptId();" >清空</a>
                </div>
            </div>

            <div class="layui-inline">
                <button type="submit" class="layui-btn" lay-submit lay-filter="getsub">查询</button>
                <button type="button" class="layui-btn" id="LAY-component-form-getval">导出</button>
            </div>
        </div>
    </div>

    <table id="mealverify" lay-filter="mealverify"></table>

   <%-- <div class="layui-table-total">
        <table cellspacing="0" cellpadding="0" border="0" class="layui-table">
            <tbody>
            <tr>
                <td data-field="userName" data-key="0-1" align="center">
                    <div class="layui-table-cell laytable-cell-1-0-0">合计行</div>
                </td>
                <td data-field="userName" data-key="0-2" align="center">
                    <div class="layui-table-cell laytable-cell-1-0-1">0</div>
                </td>
                <td data-field="userName" data-key="0-3" align="center">
                    <div class="layui-table-cell laytable-cell-1-0-2">0</div>
                </td>
                <td data-field="userName" data-key="0-4" align="center">
                    <div class="layui-table-cell laytable-cell-1-0-3">0</div>
                </td>
                <td data-field="userName" data-key="0-5" align="center">
                    <div class="layui-table-cell laytable-cell-1-0-4">0</div>
                </td>

            </tr>
            </tbody>
        </table>
    </div>--%>
</div>

<script type="application/javascript">

    //获取前一天
    // date 代表指定的日期，格式：2018-09-27
    // day 传-1表始前一天，传1表始后一天
    // JS获取指定日期的前一天，后一天
    function getNextDate(day) {
        var dd = new Date();
        dd.setDate(dd.getDate() + day);
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
        var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
        return y + "-" + m + "-" + d;
    };

    function chooseUserId(){
        user_id='userId';
        $.popWindow("../common/selectUser?0");
    }

    function chooseDeptId(){
        dept_id = 'deptId';
        $.popWindow("../common/selectDept?0");
    }

    function EmptyUserId(){
        $('#userId').removeAttr('username');
        $('#userId').removeAttr('user_id');
        $('#userId').removeAttr('dataid');
        $('#userId').removeAttr('userprivname');
        $('#userId').val('');
    }

    function EmptyDeptId(){
        $('#deptId').removeAttr('deptname');
        $('#deptId').removeAttr('deptid');
        $('#deptId').val('');
    }


    layui.use(['table','layer','form','laydate'], function () {
        var table = layui.table,
            layer = layui.layer,
            form = layui.form,
            laydate = layui.laydate;

        laydate.render({
            elem: '#stadate'
            ,value: getNextDate(1)
        });
        laydate.render({
            elem: '#enddate'
            ,value:getNextDate(1)
        });


        table.render({
            elem: '#mealverify'
            ,url: '/MealManage/getMealMap'
            ,where:{
                useFlag:true,
                stadate:getNextDate(1),
                enddate:getNextDate(1),
                college:'1',
            }
            ,parseData: function (res) {
                return {
                    "code": 0,
                    "data": res.obj,
                    "count": res.totleNum,
                };
            }
            ,page: true
            ,totalRow: true
            ,cols: [[
                {field: 'userName', title: '申请人', align: 'center',totalRowText: '合计行'}
                , {field: 'deptName', title: '部门', align: 'center'}
                , { title: '用餐类型', align: 'center', templet: function (d) {
                        if (d.mealType == '1') {
                            return "访客"
                        } else if (d.mealType == '2') {
                            return "教职工"
                        }
                    }}
                ,{field: 'breakfastNum', title: '早餐（份）', align: 'center',totalRow: true}
                ,{field: 'lunchNum', title: '中餐（份）', align: 'center',totalRow: true}
                ,{field: 'predestineTime', title: '预定时间', align: 'center'}
            ]]
        });

        form.on('submit(getsub)', function(data){
            var field = data.field;
            var userId =  $('#userId').attr('user_id');
            if (userId != undefined){
                deptid = deptid.substring(0,deptid.length-1);
                field['userId'] = userId;
            }
            var deptid =  $('#deptId').attr('deptid');
            if (deptid != undefined){
                deptid = deptid.substring(0,deptid.length-1);
                field['deptId'] = deptid;
            }

            table.reload('mealverify',{
                where:field
            });
            return false;
        });

        //导出
        layui.$('#LAY-component-form-getval').on('click', function(){
            window.open('/MealManage/getMealMap?isExport=true&stadate=' + $('#stadate').val() + '&enddate=' + $('#enddate').val() + '&mealType=' + $('#mealType').val() );
        });

        form.render();
    })
</script>
</body>
</html>
